package com.wimcorp.magic.dataloader.costs;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.wimcorp.magic.data.CostData;
import com.wimcorp.magic.input.CostInput;

public class PayLifeWidget extends CostWidget {

	private TextBox amount;

	public PayLifeWidget(CostInput cost) {
		super(cost);

		amount = new TextBox();
		createColorPanel("Amount", amount);
	}

	private void createColorPanel(String label, TextBox textBox) {
		HorizontalPanel panel = new HorizontalPanel();
		panel.add(new Label(label));
		panel.add(textBox);
		getConfigurationPanel().add(panel);
	}

	public void load(CostData cost) {
		JSONObject config = (JSONObject) JSONParser.parseLenient(cost.getConfig());
		amount.setText(toString(config.get("amount")));
	}

	public String getManaCost() {
		return amount.getText();
	}

	public String getConfig() {
		JSONObject config = new JSONObject();
		config.put("amount", new JSONString(amount.getText()));
		return config.toString();
	}

}
